import Vue from 'vue';
const showModal = Vue.extend(require('./showMod.vue').default);
let modalInstance;
let modal = {
  showModal(options) {
    /**options
     * modalContent:提示内容
     * okText: 确定按钮文字
     * cancenlText :取消按钮文字
     * callBackArgs: 回调传递参数 Object
     * **/
    if (modalInstance || typeof options != "object") return;
    modalInstance = new showModal({ propsData: options });
    if(options.hasOwnProperty("callBack")){
        let that = this;
        modalInstance.callBack = function(code,data){
            options.callBack({"code":code,"data":data});
            that.close();
        }
    }
    modalInstance.vm = modalInstance.$mount()
    document.getElementById("app").appendChild(modalInstance.vm.$el);

    Vue.nextTick(() => {
      modalInstance.modalVisible = true;
    });
  },
  close() {
    if (!modalInstance||!modalInstance.modalVisible) return;
    modalInstance.modalVisible =false;
    setTimeout(() => {
      document.getElementById("app").removeChild(modalInstance.vm.$el);
      modalInstance.$destroy();
      modalInstance = null;
    }, 300);
  },
}
export default modal; 